<?php

namespace Common\Model;
use Common\Model\XuecheModel;

class MemberPamModel extends XuecheModel {

    protected $tableName = 'member_pam';
    protected $pk = 'member_id';
    protected $fields = array(
        'member_id', 'login_account', 'login_password', 'password_account', 'disabled'
    );

    protected $_map = array(
        'account' => 'password_account',
        'pass' => 'login_password',
    );

    /**
     * 清空数据缓存
     *
     */
    public function ClearAllCache() {

    }

    //缓存设置
    protected $_useCacheType = 'file';
    protected $_catheTime = 36000;

    public function Validate($data) {
        if($data[$this->pk] > 0){
            return TRUE;
        }
        return false;
    }

    /**
     * 获取用户登录密码,检测用户名的重复
     * @param type $username
     * @return boolean
     */
    public function login($username){
        if(empty($username)){            return FALSE;}
        return $this->where("`login_account` = '{$username}' AND `disabled`='false'")->field('member_id,login_account,password_account,login_password')->find();
    }


    public function SaveData($data, $pks = array()) {
        return parent::SaveData($data, $pks);
    }

    public function checkRepart($openid){
        if($res = $this->where("`openid` = '{$openid}'")->find()){
            return $res;
        }
        return FALSE;
    }

    public function getIdByMobile($mobile){
        if(isMobile($mobile)){
            $where = "`login_account` = '{$mobile}'";
            return $this->where($where)->find();
        }
        return FALSE;
    }

}
